package hai.wom.org.qyer_destination.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import hai.wom.org.qyer_destination.R;
import hai.wom.org.qyer_destination.adapter.MyAdapter_City;
import hai.wom.org.qyer_destination.bean.HotCity;
import hai.wom.org.qyer_destination.callback.ICallback;
import hai.wom.org.qyer_destination.callback.IIndex;
import hai.wom.org.qyer_destination.callback.IList;
import hai.wom.org.qyer_destination.utils.HttpUtils;

/**
 * Created by Administrator on 2017/1/12 0012.
 */

public class Fragment_City extends Fragment implements IList, IIndex {
    private GridView gv;
    private MyAdapter_City adapter_city;
    private List<HotCity.DataEntity.DestinationsEntity> list;
    public List<HotCity.DataEntity> datas;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fg_city_layout, container, false);
        gv = (GridView) view.findViewById(R.id.gv_fg_city);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        list = new ArrayList<>();
        adapter_city = new MyAdapter_City(getContext(), list);
        gv.setAdapter(adapter_city);
    }

    //回调
    public void setSelect(int index) {
        list.clear();
        list.addAll(datas.get(index).getDestinations());
        adapter_city.notifyDataSetChanged();
    }

    @Override
    public void sendData(List<HotCity.DataEntity> datas) {
        this.datas = datas;
        setSelect(0);
    }

    @Override
    public void sendIndex(int index) {
        setSelect(index);
    }


}
